﻿using Dapper_Core.Basic;
using Dapper_Core.Table;
using System;
using System.Collections.Generic;
using System.Text;

namespace Dapper_Core.DAL.Impl
{
    public static class SyncDetailHelper
    {
        /// <summary>
        /// 同步子表明细
        /// </summary>
        /// <param name="model">需要补全属性的DTO</param>
        public static void SyncDetail(BaseModel model)
        {
            if (model == null) return;
            string tableName = model.GetType().Name;
            BaseRepository<Sys_TableRelation> baseRepository = new BaseRepository<Sys_TableRelation>(false, false);
            IEnumerable<Sys_TableRelation> relationList = baseRepository.GetList(a => a.FromTable == tableName);
            foreach (var relation in relationList)
            {
                ISyncDetail syncDetail = SyncDetailFactory.GetInstance(relation.ToTable);
                syncDetail.SyncDetail(model, relation);
            }
        }
    }
}
